package com.spring.batch.base.xml;

import org.springframework.batch.core.*;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {


    public static void main(String[] args) throws Exception {
        test1();
//        test2();
    }

    /**
     * 明确Job Instance的概念，Job Instance 是由Job的名称和执行该job的参数组成的
     */
    private static void test1() {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        JobLauncher jobLauncher = (JobLauncher) applicationContext.getBean("jobLauncher");
        Job personJob = (Job) applicationContext.getBean("personJob");

        JobParameters jobParameters = new JobParametersBuilder()
                .addLong("time", System.currentTimeMillis())//区分实例
//                .addString("", "")//参数后置
                .toJobParameters();
        try {
            JobExecution jobExecution = jobLauncher.run(personJob, jobParameters);
            System.out.println(jobExecution.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }



}